<?php

namespace app\admin\model;

use think\Model;


class QuesStudent extends Model
{


    // 表名
    protected $name = 'ques_student';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'create_time';
    protected $updateTime = 'update_time';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'create_time_text',
        'update_time_text',
        'a_1_text',
        'a_1_1_text',
        'a_1_2_text',
        'a_2_text',
        'a_2_1_text',
        'a_3_text',
        'a_3_1_text',
        'a_3_2_text',
        'a_4_text',
        'a_5_text',
        'a_5_1_text',
        'a_8_text',
        'a_8_1_text',
        'a_8_2_text',
        'a_8_3_text',
        'a_8_4_text',
        'a_9_text',
        'a_10_text',
        'a_10_1_text',
        'a_10_2_text',
        'a_11_text',
        'a_11_1_text',
        'a_12_text',
    ];

    public function getCreateTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['create_time']) ? $data['create_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getUpdateTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['update_time']) ? $data['update_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setCreateTimeAttr($value)
    {

        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setUpdateTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    public function getA_1TextAttr($value, $data)
    {
        // var_dump(config('ques.a_1')['answ']);
        return isset($data['a_1']) && isset(config('ques.a_1')['answ'][$data['a_1']]['title']) ? config('ques.a_1')['answ'][$data['a_1']]['title'] : '';
    }

    public function getA_1_1TextAttr($value, $data)
    {

        if(!isset($data['a_1']) || $data['a_1'] == 0)
            return '-';
        else
        {
            $value = $value ? $value : (isset($data['a_1_1']) ? $data['a_1_1'] : '');
            return is_numeric($value) ? date("Y-m-d", $value) : $value;
        }
    }
    protected function setA_1_1Attr($value)
    {
        return $value === '' ? 0 : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    public function getA_1_2TextAttr($value, $data)
    {

        if(!isset($data['a_1']) || $data['a_1'] == 0)
            return '-';
        else
        {
            $value = $value ? $value : (isset($data['a_1_2']) ? $data['a_1_2'] : '');
            return  $value;
        }
    }
    public function getA_2TextAttr($value, $data)
    {
        // var_dump(config('ques.a_1')['answ']);
        return isset($data['a_2']) && isset(config('ques.a_2')['answ'][$data['a_2']]['title']) ? config('ques.a_2')['answ'][$data['a_2']]['title'] : '';
    }
    public function getA_2_1TextAttr($value, $data)
    {
        if(!isset($data['a_2']) || $data['a_2'] == 0)
            return '-';
        else
        {
            $value = $value ? $value : (isset($data['a_2_1']) ? $data['a_2_1'] : '');
            return is_numeric($value) ? date("Y-m-d", $value) : $value;
        }
    }
    protected function setA_2_1Attr($value)
    {
        return $value === '' ? 0 : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    public function getA_3TextAttr($value, $data)
    {
        // var_dump(config('ques.a_1')['answ']);
        return isset($data['a_3']) && isset(config('ques.a_3')['answ'][$data['a_3']]['title']) ? config('ques.a_3')['answ'][$data['a_3']]['title'] : '';
    }
    public function getA_3_1TextAttr($value, $data)
    {
        if(!isset($data['a_3']) || $data['a_3'] == 0)
            return '-';
        else
        {
            $value = $value ? $value : (isset($data['a_3_1']) ? $data['a_3_1'] : '');
            return is_numeric($value) ? date("Y-m-d", $value) : $value;
        }
    }
    protected function setA_3_1Attr($value)
    {
        return $value === '' ? 0 : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    public function getA_3_2TextAttr($value, $data)
    {
        if(!isset($data['a_3']) || $data['a_3'] == 0)
            return '-';
        else
        {
            $value = $value ? $value : (isset($data['a_3_2']) ? $data['a_3_2'] : 0);
            return ($value == 1) ?'是':'否';
        }

    }

    public function getA_4TextAttr($value, $data)
    {
        // var_dump(config('ques.a_1')['answ']);
        return isset($data['a_4']) && isset(config('ques.a_4')['answ'][$data['a_4']]['title']) ? config('ques.a_4')['answ'][$data['a_4']]['title'] : '';
    }

    public function getA_5TextAttr($value, $data)
    {
        // var_dump(config('ques.a_1')['answ']);
        return isset($data['a_5']) && isset(config('ques.a_5')['answ'][$data['a_5']]['title']) ? config('ques.a_5')['answ'][$data['a_5']]['title'] : '';
    }

    public function getA_5_1TextAttr($value, $data)
    {
        if(!isset($data['a_5']) || $data['a_5'] == 0)
            return '-';
        else
        {
            $value = $value ? $value : (isset($data['a_5_1']) ? $data['a_5_1'] : '');
            return is_numeric($value) ? date("Y-m-d", $value) : $value;
        }
    }
    protected function setA_5_1Attr($value)
    {
        return $value === '' ? 0 : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setA_11_1Attr($value)
    {
        return $value === '' ? 0 : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    public function getA_8TextAttr($value,$data){
        return isset($data['a_8']) && isset(config('ques.a_8')['answ'][$data['a_8']]['title']) ? config('ques.a_8')['answ'][$data['a_8']]['title'] : '';
    }

    public function getA_8_1TextAttr($value, $data)
    {
        if(!isset($data['a_8']) || $data['a_8'] == 0)
            return '-';
        else
        {
            $value = $value ? $value : (isset($data['a_8_1']) ? $data['a_8_1'] : '');
            return  $value;
        }
    }

    public function getA_8_2TextAttr($value, $data)
    {
        if(!isset($data['a_8']) || $data['a_8'] == 0)
            return '-';
        else
        {
            $value = $value ? $value : (isset($data['a_8_2']) ? $data['a_8_2'] : '');
            return  $value;
        }
    }
    public function getA_8_3TextAttr($value, $data)
    {
        if(!isset($data['a_8']) || $data['a_8'] == 0)
            return '-';
        else
        {
            $value = $value ? $value : (isset($data['a_8_3']) ? $data['a_8_3'] : '');
            return  $value;
        }
    }
    public function getA_8_4TextAttr($value, $data)
    {
        if(!isset($data['a_8']) || $data['a_8'] == 0)
            return '-';
        else
        {
            $value = $value ? $value : (isset($data['a_8_4']) ? $data['a_8_4'] : '');
            return  $value;
        }
    }

     public function getA_9TextAttr($value, $data)
    {
        // var_dump(config('ques.a_1')['answ']);
        return isset($data['a_9']) && isset(config('ques.a_9')['answ'][$data['a_9']]['title']) ? config('ques.a_9')['answ'][$data['a_9']]['title'] : '';
    }

    public function getA_10TextAttr($value, $data)
    {
        // var_dump(config('ques.a_1')['answ']);
        return isset($data['a_10']) && isset(config('ques.a_10')['answ'][$data['a_10']]['title']) ? config('ques.a_10')['answ'][$data['a_10']]['title'] : '';
    }
    public function getA_10_1TextAttr($value, $data)
    {
        if(isset($data['a_10']) && $data['a_10'] == 1 )
            return isset($data['a_10_1']) && isset(config('ques.a_10_1')['answ'][$data['a_10_1']]['title']) ? config('ques.a_10_1')['answ'][$data['a_10_1']]['title'] : '';
        else
            return '-';
    }
    public function getA_10_2TextAttr($value, $data)
    {
        if(isset($data['a_10']) && $data['a_10'] == 1 )
            return isset($data['a_10_2']) && isset(config('ques.a_10_2')['answ'][$data['a_10_2']]['title']) ? config('ques.a_10_2')['answ'][$data['a_10_2']]['title'] : '';
        else
            return '-';
    }

    public function getA_11TextAttr($value, $data)
    {
        // var_dump(config('ques.a_1')['answ']);
        return isset($data['a_11']) && isset(config('ques.a_11')['answ'][$data['a_11']]['title']) ? config('ques.a_11')['answ'][$data['a_11']]['title'] : '-';
    }
    public function getA_11_1TextAttr($value, $data)
    {
        if(!isset($data['a_11_1']) || $data['a_11_1'] == 0)
            return '-';
        else
        {
            $value = $value ? $value : (isset($data['a_11_1']) ? $data['a_11_1'] : '');
            return is_numeric($value) ? date("Y-m-d", $value) : $value;
        }
    }

    public function getA_12TextAttr($value, $data)
    {
        // var_dump(config('ques.a_1')['answ']);
        return isset($data['a_12']) && isset(config('ques.a_12')['answ'][$data['a_12']]['title']) ? config('ques.a_12')['answ'][$data['a_12']]['title'] : '';
    }
}
